package com.ztjava.weixin.controller;

import com.jfinal.kit.Ret;
import com.ztjava.core.Constant;
import com.ztjava.core.annotation.ControllerClass;
import com.ztjava.core.base.BaseController;
import com.ztjava.core.client.member.MobileClient;
import com.ztjava.ext.auth.annotation.UserController;
import com.ztjava.plugin.weixin.WeixinKit;
import com.ztjava.plugin.weixin.WeixinSdk;

@ControllerClass(client=MobileClient.class,path="/weixin")
@UserController(portal=Constant.P_MEMBER)
public class WeixinController extends BaseController{
	public void jsConfig(){
		WeixinSdk weixinSdk = WeixinKit.use();
		String url = getPara("url");
		Ret ret = weixinSdk.getJsConfig(url);
		setAttr("appid", ret.get("appid"));
		setAttr("noncestr", ret.get("noncestr"));
		setAttr("timestamp", ret.get("timestamp"));
		setAttr("sign", ret.get("sign"));
		setAttr(Constant.RESULT, Constant.SUCCESS);
		renderJson(new String[]{Constant.RESULT,"noncestr","sign","timestamp","appid"});
	}
	
	public void downMedia(){
		String media_id = getPara("media_id");
		WeixinSdk weixinSdk = WeixinKit.use();
		String url = weixinSdk.media_get_file(media_id);
		setAttr(Constant.RESULT, Constant.SUCCESS);
		setAttr("url", url);
		renderJson(new String[]{Constant.RESULT,"url"});
	}
}
